home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Variant Records in C ... Is there a way ?
- Date: 22 Mar 1996 11:24:41 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4iuuppINN3s2@keats.ugrad.cs.ubc.ca>
- References: <Pine.OSF.3.91.960319170252.9783B-100000@alfa.ist.utl.pt> <315006F8.639@cmt.lpr.mail.carel.fi> <4iumf8$604@madeline.INS.CWRU.Edu>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4iumf8$604@madeline.INS.CWRU.Edu>,
- Michael A. Balfour <mab22@po.CWRU.Edu> wrote:
- >
- >In a previous article, aril@cmt.lpr.mail.carel.fi (Ari Lukumies) says:
- >
- >>How about something like:
- >>
- >> struct {
- >> int flag;
- >> union {
- >> char text[80];
- >> int num;
- >> double fpoint;
- >> } data;
- >> } test;
- >>
- >
- >Wasn't the original goal of the variant records to avoid chewing up
- >extra memory? As I understand it, union uses as much memory as the
- >largest member. In this case, even if you are only storing an int, you
- >still use 80 bytes, right?
-
- I don't think that you are right on this one, but I would have to do a little
- digging to be sure. In Pascal, it will also be true that the variant record
- will take up the same space as the largest member. This has to be the case,
- simply, because the type field is dynamic, not static. What would happen if you
- made an array of variant records, and then decided to switch their type?
-
- If you want to avoid ``chewing memory'', a language with ``is-a'' inheritance,
- such as Oberon, will do the trick. You would declare a few members as a base
- record, and then extend it in various ways into derived objects of various
- lengths.
-
- I will check up on the Pascal semantics of variant records when next I have the
- opportunity.
- --
-
-